package com.future.gateway.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @Author: liuby5
 * @CreateTime: 2023-05-06  16:53
 * @Description: 全局网关配置
 * @Version: 1.0
 */
@Configuration
@Slf4j
@Component
public class GlobalRouterConfig {
    /**
     * 配置网关跳转路由
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {

        return builder.routes()
                .route("future-auth", r -> r.path("/auth/**")
                        .filters(f -> f.stripPrefix(1))
                        .uri("http://127.0.0.1:3000"))
                .route("future-admin", r -> r.path("/admin/**")
                        .filters(f -> f.stripPrefix(1))
                        .uri("http://127.0.0.1:4000"))
                .route("future-gateway", r -> r.path("/gateway/**")
                        .filters(f -> f.stripPrefix(1))
                        .uri("http://127.0.0.1:9999"))
                .build();
    }
}
